/* 
 * $Id: Subscriber.java 473 2008-10-19 19:58:23Z willie $
 * 
 * Copyright 2008 Wheeler Software.
 */
package springinpractice.ch8.mailinglist.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Email;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Length;
import org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank;

/**
 * @author Willie Wheeler and John Wheeler
 * Book : 'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 **/

@Entity
@Table(name = "subscriber")
public final class Subscriber {
	private Long id;
	
	@NotBlank
	@Length(max = 40)
	private String firstName;
	
	@NotBlank
	@Length(max = 40)
	private String lastName;
	
	@NotBlank
	@Email
	@Length(max = 80)
	private String email;
	
	private boolean confirmed = false;
	private boolean enabled = false;
	private String ipAddress;
	private Date dateCreated;
	
	public Subscriber() {
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	public Long getId() {
		return id;
	}
	
	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "first_name")
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "last_name")
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "email")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	@Column(name = "confirmed")
	public boolean isConfirmed() {
		return confirmed;
	}
	
	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}
	
	@Column(name = "enabled")
	public boolean isEnabled() {
		return enabled;
	}
	
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	@Column(name = "ip_addr")
	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	
	@Column(name = "date_created")
	public Date getDateCreated() {
		return dateCreated;
	}
	
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	
	@Override
	public String toString() {
		return new ToStringBuilder(this)
			.append("id", id)
			.append("firstName", firstName)
			.append("lastName", lastName)
			.append("email", email)
			.append("confirmed", confirmed)
			.append("enabled", enabled)
			.append("ipAddress", ipAddress)
			.append("dateCreated", dateCreated)
		.toString();
	}
}
